package com.eastfair.venueservice.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.venueservice.dto.LoadOrderDTO;
import com.eastfair.venueservice.dto.LogisticsOrderPageQuery;
import com.eastfair.venueservice.service.LogisticsOrderService;
import com.eastfair.venueservice.vo.LogisticsOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import javax.annotation.Resource;

/**
 * @author Du Xiaobo
 * @date 2023/5/9 11:05
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/logistics/order")
@Api(value = "LogisticsOrder", tags = "智慧物流-物流订单")
@PreAuth(replace = "common:logisticsorder:")
public class LogisticsOrderController {


    @Resource
    private LogisticsOrderService logisticsOrderService;

    @SysLog("新增装卸订单")
    @PostMapping("/load/save")
    @ApiOperation(value = "新增装卸订单", notes = "新增装卸订单")
    public R<Long> saveLoadOrder(@RequestBody LoadOrderDTO dto) {
        return R.success(logisticsOrderService.saveLoadOrder(dto));
    }

    @SysLog("修改装卸订单")
    @PostMapping("/load/update")
    @ApiOperation(value = "修改装卸订单", notes = "修改装卸订单")
    public R<Boolean> updateLoadOrder(@RequestBody LoadOrderDTO dto) {
        logisticsOrderService.updateLoadOrder(dto);
        return R.success(true);
    }
    @SysLog("通过Id查询物流订单详情")
    @GetMapping("/get/{id}")
    @ApiOperation(value = "通过Id查询物流订单详情", notes = "通过Id查询物流订单详情")
    public R<LogisticsOrderVo> getLogisticsOrderById(@PathVariable("id") Long id){
        return R.success(logisticsOrderService.getLogisticsOrderById(id));
    }


    @SysLog("查询物流订单列表")
    @PostMapping("/query/page")
    @ApiOperation(value = "查询物流订单列表", notes = "查询物流订单列表")
    public R<Page<LogisticsOrderVo>> queryLogisticsOrderPage(@RequestBody PageParams<LogisticsOrderPageQuery> pageParams){
        return R.success(logisticsOrderService.queryLogisticsOrderPage(pageParams));
    }
}
